import { createHookConfig, DisposableCollection } from '@antv/xflow'
import { POINT_NODE_KEY, NODE_KEY } from '../constants'
import { AutoBan, PointNode, DecisionNode } from '../node'

const graphConfig = {
  // grid: false,
  resizing: false,
  selecting: false,
  // connector: {
  //   name: 'rounded',
  //   args: {
  //     radius: 20,
  //   },
  // },
}

export const useGraphHookConfig = createHookConfig((config, proxy) => {
  // 获取 Props
  // const props = proxy.getValue()
  // console.log('get main props', props)
  config.setRegisterHook(hooks => {
    const disposableList = [
      // 注册增加 react Node Render
      hooks.reactNodeRender.registerHook({
        name: 'react node render',
        handler: async renderMap => {
          renderMap.set('AUTO_BAN', AutoBan)
          renderMap.set('DECISION', DecisionNode)
          renderMap.set(POINT_NODE_KEY, PointNode)
        }
      }),
      hooks.graphOptions.registerHook({
        name: 'xflow-options',
        handler: async args => {
          Object.assign(args, graphConfig)
        }
      })
    ]
    const toDispose = new DisposableCollection()
    toDispose.pushAll(disposableList)
    return toDispose
  })
})
